package com.cat.mrli.rat.util;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.RawRes;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * Created by MrLi on 2017/6/21.
 */

public final class TextResourceReader {

    public static String readTextFiledFormResource(@NonNull Context c, @RawRes int resource) {
        StringBuilder builder = new StringBuilder();
        try {
            InputStream in = c.getResources().openRawResource(resource);
            InputStreamReader inputReader = new InputStreamReader(in);
            BufferedReader bufferedReader = new BufferedReader(inputReader);
            String nextLine;
            while ((nextLine = bufferedReader.readLine()) != null) {
                builder.append(nextLine);
                builder.append('\n');
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return builder.toString();
    }

}
